package com.example.campuslink.viewModel

import android.content.Intent
import android.os.Bundle
import androidx.core.content.ContentProviderCompat.requireContext
import androidx.lifecycle.MutableLiveData
import com.example.campuslink.commen.tools.putExtraKey
import com.example.campuslink.model.ChoiceFilePathData
import com.example.campuslink.ui.activity.PublicActivity

class PhotoViewModel : BaseViewModel() {
    private val _isShowNext = MutableLiveData<Boolean>()
    val isShowNext get() = _isShowNext
    fun setIsShowNext(isShow: Boolean) {
        _isShowNext.value = isShow
    }

    private val _fileType = MutableLiveData<String>()
    val fileType get() = _fileType
    fun setFileType(type: String) {
        _fileType.value = type
    }

    private val _allFilePath = MutableLiveData<MutableList<ChoiceFilePathData>>(mutableListOf())
        val allFilePath get() = _allFilePath

    fun changeFilePath(path: MutableList<ChoiceFilePathData>) {
        _allFilePath.value = path
    }

    fun jumpToPublicActivity(){
        // 获取当前值（如果为null则使用空列表）
        val currentList = _allFilePath.value ?: mutableListOf()
        val path = currentList.filter { it.isChoice }.map { it.path }

        val bundle = Bundle().apply {
            putSerializable(putExtraKey.ALL_FILE_PATH.key, ArrayList(path))
        }

        // 启动Activity
        startActivity(
            Intent(context, PublicActivity::class.java).apply {
                putExtras(bundle)
            }, targetClass = PublicActivity::class.java
        )
    }
}